home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CreatingGames / Utilities / Misc / MapMaster / clanguagesupport / include / mapmaster / mapfunctions.h < prev   
Encoding:
C/C++ Source or Header  |  1997-08-18  |  5.0 KB  |  156 lines

  1. /***************************************/
  2. /*  Block Routines for C Language V1.0 */
  3. /*  Written by Kelly Samel             */
  4. /*  Email- samel@telusplanet.net       */
  5. /***************************************/
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <intuition/intuition.h>
  9. #include <graphics/gfx.h>
  10. #include <mapmaster/iff.h> /* Include file for iff.library */
  11. #include <clib/intuition_protos.h>
  12. #include <clib/graphics_protos.h>
  13. #include <clib/exec_protos.h>
  14. #include <clib/dos_protos.h>
  15.  
  16. /* must be defined in your source code */
  17. extern mapdata[];
  18.  
  19. /******************************/
  20. /*  ProtoTypes for Functions  */
  21. /******************************/
  22. void LoadMap(char filename[],int horizblocks,int vertblocks);
  23. void GetBlocks(char blocksfile[],struct BitMap *tempbitmap,int depth,int bmwidth,int bmheight);
  24. void GetBlocksPalette(char blocksfile[],struct Screen *screen);
  25. void FreeBlocks(struct BitMap *tempbitmap,int depth);
  26. void PasteBlocks(int horizblocks,int vertblocks,int blockwidth,int blockheight,int blockgap,int xoffset,int yoffset,struct BitMap *source,struct BitMap *dest);
  27.  
  28. /************************************************/
  29. /* Loads the map data into your mapdata[] Array */
  30. /************************************************/
  31. void LoadMap(char filename[],int horizblocks,int vertblocks)
  32. {
  33. /* Setup required variables */
  34. FILE *mapfile;
  35. char tempstring[11];
  36. int n=1;
  37.  
  38. /* Open the mapfile for reading */
  39. mapfile=fopen(filename,"r");
  40.  
  41. /* Loop to read the mapdata */
  42. while (n<horizblocks*vertblocks+1)
  43. {
  44. fgets(tempstring,10,mapfile);
  45. mapdata[n]=atoi(tempstring);
  46. n++;}
  47.  
  48. /* Close the mapfile */
  49. fclose(mapfile);
  50. }
  51.  
  52. /***********************************************************************/
  53. /* GetBlocks loads IFF picture data into a bitmap to be used as blocks */
  54. /***********************************************************************/
  55. void GetBlocks(char blocksfile[],struct BitMap *tempbitmap,int depth,int bmwidth,int bmheight)
  56. {
  57. /* Setup and initialize required variables */
  58. struct Library *IFFBase;
  59. IFFL_HANDLE iff; BOOL success;
  60. int DEPTH;
  61. DEPTH=depth; depth=0;
  62.  
  63. /* Initialize and allocate memory for the BitMap */
  64. /* that will hold your blocks */
  65. InitBitMap(tempbitmap,DEPTH,bmwidth,bmheight);
  66. for(depth=0; depth<DEPTH; depth++)
  67.     {tempbitmap->Planes[depth] = AllocRaster(bmwidth,bmheight);}
  68.  
  69. /* Open iff.library v23 */
  70. IFFBase=OpenLibrary("iff.library",23);
  71.  
  72. /* Load the Picture into memory using iff.library V23 */
  73. iff=IFFL_OpenIFF(blocksfile,IFFL_MODE_READ);
  74. success=IFFL_DecodePic(iff,tempbitmap);
  75.  
  76. /* Close what we opened */
  77. IFFL_CloseIFF(iff);
  78. CloseLibrary(IFFBase);
  79. }
  80.  
  81. /*************************************************************/
  82. /*   Gets color Palette from blocks and loads it into screen */
  83. /*************************************************************/
  84. void GetBlocksPalette(char blocksfile[],struct Screen *screen)
  85. {
  86. /* Setup and initialize required variables */
  87. struct Library *IFFBase;
  88. IFFL_HANDLE iff; 
  89. UWORD colors[256]; int numcol;
  90.  
  91. IFFBase=OpenLibrary("iff.library",23);
  92.  
  93. /* Load the Picture and get colors from it */
  94. iff=IFFL_OpenIFF(blocksfile,IFFL_MODE_READ);
  95. numcol=IFFL_GetColorTab(iff,colors);
  96.  
  97. /* Load the colors into screen */
  98. LoadRGB4(&screen->ViewPort,colors,numcol);
  99.  
  100. /* Close what we opened */
  101. IFFL_CloseIFF(iff);
  102. CloseLibrary(IFFBase);
  103. }
  104.  
  105. /****************************************/
  106. /* Frees memory allocated by GetBlocks  */
  107. /****************************************/
  108. void FreeBlocks(struct BitMap *tempbitmap,int depth)
  109. {
  110. int DEPTH;
  111. DEPTH=depth; depth=0;
  112. /* Free memory allocated for BitMap that holds your blocks */
  113. for(depth=0; depth<DEPTH; depth++)
  114.     {FreeRaster(tempbitmap->Planes[depth],tempbitmap->BytesPerRow*8,tempbitmap->Rows);}
  115. }
  116.  
  117. /********************************************************************************/
  118. /* Pastes the blocks from source BitMap to a Destination BitMap using mapdata[] */
  119. /********************************************************************************/
  120. void PasteBlocks(int horizblocks,int vertblocks,int blockwidth,int blockheight,int blockgap,int xoffset,int yoffset,struct BitMap *source,struct BitMap *dest)
  121. {
  122. /* Setup and initialize Required Variables */
  123. int x; int y; int x2; int y2;
  124. int n; int n2; int counter; int done;
  125. int totalwidth; int totalheight;
  126. x=0; y=0; counter=1; done=0;
  127. x2=0; y2=0;
  128. n=1; n2=2;
  129. totalwidth=(source->BytesPerRow*8)/(blockwidth+blockgap)-1;
  130. totalheight=source->Rows/(blockheight+blockgap);
  131.  
  132. /* Loop to paste blocks to screen */
  133. while(n<horizblocks*vertblocks+1)
  134. {
  135. /* loop to decide the coordinates to get the pasting block from */
  136. while(counter<mapdata[n])
  137. {
  138. if(x==totalwidth){x=0; y++; counter++;}
  139. if(counter==mapdata[n]){done=1;}
  140. if(x<totalwidth && done==0){x++; counter++;}
  141. }
  142. /* Paste the current block using supplied parameters */
  143. BltBitMap(source,x*(blockwidth+blockgap)+blockgap,y*(blockheight+blockgap)+blockgap,dest,x2+xoffset,y2+yoffset,blockwidth,blockheight,0xC0,0xff,NULL);
  144.  
  145. /* Reset the variables */
  146. counter=1; x=0; y=0; done=0;
  147.  
  148. /* Keep it pasting in the right place */
  149. x2=x2+blockwidth;
  150. if (n==horizblocks){y2=y2+blockheight; x2=0;}
  151. if (n==horizblocks*n2){y2=y2+blockheight; x2=0; n2++;}
  152.  
  153. n++;}
  154.  
  155. }
  156.